import router from './index.js';

// 白名单
const whileList = ['/login'];

// 将导航守卫挂载到Router上，to，即将要去的页面，form，正要离开的页面。next，决定是否可以放行
router.beforeEach((to, from, next) => {
  // console.log(to, from);
  if (whileList.indexOf(to.path) !== -1) {
    next();
  } else {
    const token = window.sessionStorage.getItem('token');
    if (token) {
      next();
    } else {
      next('/');
    }
  }
});
